package com.itheima.controller.pms;

import com.itheima.api.pms.PmsProductCategoryService;
import com.itheima.vo.domain.AjaxResult;
import com.itheima.vo.dto.pms.PmsProductCategoryDto;
import com.itheima.vo.pojo.PmsProductCategory;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("productCategory")
public class PmsProductCategoryController {

    @DubboReference
    private PmsProductCategoryService pmsProductCategoryService;

    /**
     * 1.添加商品分类
     *
     * @param pmsProductCategoryDto
     * @return
     */
    @PostMapping("create")
    public AjaxResult create(@RequestBody PmsProductCategoryDto pmsProductCategoryDto) {
        return pmsProductCategoryService.create(pmsProductCategoryDto);
    }

    /**
     * 2.删除商品分类
     *
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public AjaxResult deleteBatch(@PathVariable(value = "id", required = true) Integer id) {
        return pmsProductCategoryService.deleteById(id);
    }

    /**
     * 3.查询所有一级分类及子分类
     *
     * @return
     */
    @GetMapping("list/withChildren")
    public AjaxResult getListWithChildren() {
        return pmsProductCategoryService.getListWithChildren();
    }

    /**
     * 4.分页查询商品分类
     *
     * @param parentId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list/{parentId}")
    public AjaxResult ListByParentId(@PathVariable(value = "parentId", required = true) Integer parentId,
                                     @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return pmsProductCategoryService.ListByParentId(parentId, pageNum, pageSize);
    }

    /**
     * 5.修改导航栏显示状态
     *
     * @param ids
     * @param navStatus
     * @return
     */
    @PostMapping("update/navStatus")
    public AjaxResult updateByNavStatus(@RequestParam(value = "ids", required = true) ArrayList<Integer> ids,
                                        @RequestParam(value = "navStatus", required = true) Integer navStatus) {
        return pmsProductCategoryService.updateByNavStatus(ids, navStatus);
    }

    /**
     * 6.修改显示状态
     * @param ids
     * @param showStatus
     * @return
     */
    @PostMapping("update/showStatus")
    public AjaxResult updateByShowStatus(@RequestParam(value = "ids", required = true) ArrayList<Integer> ids,
                                         @RequestParam(value = "showStatus", required = true) Integer showStatus) {
        return pmsProductCategoryService.updateByShowStatus(ids, showStatus);
    }

    /**
     * 7.修改商品分类
     * @param id
     * @param pmsProductCategoryDto
     * @return
     */
    @PostMapping("update/{id}")
    public AjaxResult updateById(@PathVariable(value = "id", required = true) Integer id,
                                         @RequestBody PmsProductCategoryDto pmsProductCategoryDto) {
        return pmsProductCategoryService.updateById(id, pmsProductCategoryDto);
    }

    /**
     * 8.根据id获取商品分类
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public AjaxResult findById(@PathVariable(value = "id", required = true) Integer id) {
        return pmsProductCategoryService.findById(id);
    }

    //121231234
}
